
/****** Object:  Stored Procedure [dbo].[sBaoCaoDoanhThuCuaSanPham] Script Date: 6/12/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[sBaoCaoDoanhThuCuaSanPham]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[sBaoCaoDoanhThuCuaSanPham]
GO
/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		04/07/2012	SongTM/TamPM			Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].[sBaoCaoDoanhThuCuaSanPham]
(
	@MaSanPham nvarchar(12),
	@TuNgay datetime,
	@DenNgay datetime
)

WITH ENCRYPTION
AS

if(len(@MaSanPham)=0) set @MaSanPham = null

	if (@MaSanPham is null)
		select distinct * from v_DoanhThuSanPham
		WHERE (@TuNgay is null) or (convert(date,@TuNgay) <= convert(date,NgayXuatkho))
		AND	(@DenNgay is null) or (convert(date,@DenNgay) >= convert(date,NgayXuatkho))
	else
		select distinct * from v_DoanhThuSanPham dt
		where dt.mathuoc = @MaSanPham
		AND (@TuNgay is null) or (convert(date,@TuNgay) <= convert(date,NgayXuatkho))
		AND	(@DenNgay is null) or (convert(date,@DenNgay) >= convert(date,NgayXuatkho))
		
Select * FROM tbl_Congty
GO

--GRANT EXECUTE ON [dbo].[spPhieuXuatGetList] TO [sa]
--GO
